package indi.zhifa.study2025.oa.admin.controller;

import indi.zhifa.engine.core.common.web.ann.ZhiFaRestController;
import indi.zhifa.study2025.oa.admin.facade.role.IRoleFacade;
import indi.zhifa.study2025.oa.common.util.ConstantUtil;
import indi.zhifa.study2025.oa.dao.po.GenRoleEntity;
import indi.zhifa.study2025.oa.model.expose.role.dto.RoleCreateDto;
import indi.zhifa.study2025.oa.model.expose.role.dto.RoleEditDto;
import indi.zhifa.study2025.oa.model.expose.role.dto.RoleGroupCreateDto;
import indi.zhifa.study2025.oa.model.expose.role.dto.RoleGroupEditDto;
import indi.zhifa.study2025.oa.model.expose.role.vo.RoleGroupAllVo;
import indi.zhifa.study2025.oa.model.expose.role.vo.RoleGroupVo;
import indi.zhifa.study2025.oa.model.expose.role.vo.RoleVo;
import indi.zhifa.study2025.oa.service.role.IRoleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Validated
@RequiredArgsConstructor
@Tag(name = "角色接口")
@ZhiFaRestController
@RequestMapping(ConstantUtil.API_PREFIX + "/roleMgr")
public class RoleController {

    final IRoleFacade mRoleFacade;

    @Operation(summary = "创建角色组")
    @PostMapping("/group")
    public RoleGroupVo createRoleGroup(@RequestBody RoleGroupCreateDto pRoleGroupCreateDto){
        return mRoleFacade.createRoleGroup(pRoleGroupCreateDto);
    }

    @Operation(summary = "创建角色")
    @PostMapping("/group/{id}/role")
    public RoleVo createRole(@PathVariable("id") Long pGroupId, @RequestBody RoleCreateDto pRoleCreateDto){
        return mRoleFacade.createRole(pGroupId, pRoleCreateDto);
    }

    @Operation(summary = "编辑角色组")
    @PostMapping("/group/{id}/edit")
    public RoleGroupVo editRoleGroup(@PathVariable("id") Long pId, @RequestBody RoleGroupEditDto pRoleGroupEditDto){
        return mRoleFacade.editRoleGroup(pId, pRoleGroupEditDto);
    }

    @Operation(summary = "编辑角色")
    @PostMapping("/role/{id}/edit")
    public RoleVo editRole(@PathVariable("id") Long pId, @RequestBody RoleEditDto pRoleEditDto){
        return mRoleFacade.editRole(pId, pRoleEditDto);
    }

    @Operation(summary = "查看所有角色")
    @GetMapping("/all")
    public List<RoleGroupAllVo> roleGroupAll(){
        return mRoleFacade.list();
    }

    @Operation(summary = "分配菜单")
    @PostMapping("/role/{id}/assignMenu")
    public void assignMenu(@PathVariable("id") Long pId, @RequestBody List<Long> pMenuIds){
        mRoleFacade.assignMenu(pId, pMenuIds);
    }


}
